﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Security.Cryptography;

namespace Quanlytruongtruongtieuhoc
{
    class clsKetnoi
    {
        public static SqlConnection con;
        public static void taoKetnoi()
        {
            try
            {
            con=new SqlConnection("Data Source=HUY-PC\\SQLEXPRESS;Initial Catalog=LVTN;Integrated Security=True");
            con.Open();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public static void huyKetnoi()
        {
            con.Close();
        }
        //Ham chuyen chuoi sang MD5
        static string GetMd5Hash(MD5 md5Hash, string input)
        {
            byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
            StringBuilder sBuilder = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            return sBuilder.ToString();
        }
        public static string toMD5(string pass)
        {
            using (MD5 md5 = MD5.Create())
            {
                return GetMd5Hash(md5, pass);
            }
        }
    }
}
